package com.netease.nie.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.netease.nie.base.controllers.BaseController;
import com.netease.nie.base.exceptions.BusinessException;
import com.netease.nie.constants.BusinessConstants;
import com.netease.nie.dto.CreditHistoryDto;
import com.netease.nie.facade.CreditHistoryFacade;

/**
 * 积分历史
 * @author wwbn3695
 * @CreateDate Jul 19, 2016
 */
@RestController
@RequestMapping("/api/user")
public class CreditHistoryController extends BaseController{
	
	@Autowired
	private CreditHistoryFacade creditHistoryFacade;
	
	@RequestMapping(value = "/credit_history", method = RequestMethod.GET, produces = "application/json")
	public String history(HttpServletRequest request) {
		Long userId = (Long) request.getAttribute("userId");
		if (userId == null)
			throw new BusinessException(BusinessConstants.USER_NOT_LOGIN.getCode(), "用户未登录");
		if (userId <= 0)
			throw new BusinessException(BusinessConstants.INVALID_USER_ID.getCode(), "用户id不合法");
		
		List<CreditHistoryDto> creditHistoryDtoList = creditHistoryFacade.queryCreditHistoryByUserId(userId);
		return jsonSuccess(creditHistoryDtoList);
	}
}
